<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/master' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>系统管理</el-breadcrumb-item>
                <el-breadcrumb-item>日志管理</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框:model="双向绑定表单的数据"-->
            <el-form :inline="true" :model="logFormData" class="demo-form-inline">
                <el-form-item>
                    <el-input v-model="logFormData.title" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="logFormData.startDate" type="date" placeholder="请输开始时间"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="logFormData.endDate" type="date" placeholder="请输入结束时间"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="quere"> 查询</el-button>
                </el-form-item>
               <!-- <el-form-item>
                    <el-button type="primary" > 导出</el-button>
                </el-form-item>-->
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="operId"
                            label="编号"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="title"
                            label="标题"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="method"
                            label="方法">
                    </el-table-column>
                    <el-table-column
                            prop="operName"
                            label="操作人">
                    </el-table-column>
                    <el-table-column
                            prop="operUrl"
                            label="请求路径">
                    </el-table-column>
                    <el-table-column
                            prop="operIp"
                            label="IP">
                    </el-table-column>

                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-popconfirm
                                    confirm-button-text='好的'
                                    cancel-button-text='取消'
                                    icon="el-icon-info"
                                    icon-color="red"
                                    title="确定删除日志么"
                                    @confirm= removeOperLog(scope.row.operId)>
                                <el-button type="danger" icon="el-icon-delete" circle slot="reference"></el-button>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
                <!--                分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>
    </div>

</template>

<script>
    export default {
        name: "Log",
        data() {
            return {
                //每页展示条数
                pageSize: 5,
                //当前的显示的页码
                currentPage: 1,
                //表格数据
                tableData: [],
                //总条数
                total: 0,
                //条件搜索对象
                logFormData: {}
            }
        },
        created() {
            this.initOperLogTable();
        },
        methods: {
            handleSizeChange(v){
                this.pageSize = v;
                this.initOperLogTable();
            },
            //切换页码时触发该方法
            handleCurrentChange(v){
                this.currentPage = v;
                this.initOperLogTable();
            },
            quere() {
                this.initOperLogTable()
            },
            /*exportlog() {
                var that = this;
                this.$http.get("/system/log/exportlogs").then(function (response) {
                   that.$message.success(response.data.message)
                })
            },*/

            initOperLogTable() {
                var that = this;
                this.$http.post(`/system/log/operlog/${this.currentPage}/${this.pageSize}`,this.logFormData).then(function (response) {
                    that.tableData = response.data.result.tableData.records;
                    that.total = response.data.result.tableData.total;
                });
            },
            removeOperLog(operId) {
                var that = this;
                this.$http.delete(`/system/log/del/${operId}`).then(function (response) {
                    that.$message.success(response.data.message)
                    that.initOperLogTable();
                    // location.reload();
                });
                this.currentPage=1;

            }

        }

    }
</script>

<style scoped>

</style>